using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VAMKSTMT
    {
        public DataRow Convert2AMKSTMT(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryAMKSTMT(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["AMKMANDANT"] = " ".PadRight(2 ); 
         dwReturn["AMKPKSTKRS"] = " ".PadRight(2 ); 
         dwReturn["AMKPKST"] = " ".PadRight(4 ); 
         dwReturn["AMKMTYP"] = " ".PadRight(8 ); 
         dwReturn["AMKMASCHZL"] = " ".PadRight(0 ); 
         dwReturn["AMKEINH"] = " ".PadRight(10 ); 
         dwReturn["AMKFAKTOR"] = " ".PadRight(12 ); 
         dwReturn["AMKAKSTKRS"] = " ".PadRight(2 ); 
         dwReturn["AMKAKST"] = " ".PadRight(4 ); 
         dwReturn["AMKMNRKRS"] = " ".PadRight(2 ); 
         dwReturn["AMKMLFDNR"] = " ".PadRight(4 ); 
         dwReturn["AMKMPOS"] = " ".PadRight(2 ); 
         dwReturn["AMKANZ1"] = " ".PadRight(0 ); 
         dwReturn["AMKABT1"] = " ".PadRight(0 ); 
         dwReturn["AMKANZ2"] = " ".PadRight(0 ); 
         dwReturn["AMKABT2"] = " ".PadRight(0 ); 
         dwReturn["AMKANZ3"] = " ".PadRight(0 ); 
         dwReturn["AMKABT3"] = " ".PadRight(0 ); 
         dwReturn["AMKANZ4"] = " ".PadRight(0 ); 
         dwReturn["AMKABT4"] = " ".PadRight(0 ); 
         dwReturn["AMKANZ5"] = " ".PadRight(0 ); 
         dwReturn["AMKABT5"] = " ".PadRight(0 ); 
         dwReturn["AMKANZ6"] = " ".PadRight(0 ); 
         dwReturn["AMKABT6"] = " ".PadRight(0 ); 
         dwReturn["AMKANZ7"] = " ".PadRight(0 ); 
         dwReturn["AMKABT7"] = " ".PadRight(0 ); 
         dwReturn["AMKANZ8"] = " ".PadRight(0 ); 
         dwReturn["AMKABT8"] = " ".PadRight(0 ); 
         dwReturn["AMKFILLER"] = " ".PadRight(18 ); 
         dwReturn["AMKAENDZL"] = " ".PadRight(0 ); 
         dwReturn["AMKAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["AMKAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["AMKNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["AMKNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapAMKSTMT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveAMKSTMT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryAMKSTMT(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapAMKSTMT(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertAMKSTMT(dwLocal, ITXDBVERSION);
            }
            UpdateAMKSTMT(dwLocal);
        }
        public void InsertAMKSTMT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO AMKSTMT(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryAMKSTMT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM AMKSTMT WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM AMKSTMT  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "AMKSTMT";
            Return = Result;
            return Return;
        }
        public void DeleteAMKSTMT(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM AMKSTMT   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateAMKSTMT(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE AMKSTMT SET "
                    +"AMKMANDANT= :AMKMANDANT,"
                    +"AMKPKSTKRS= :AMKPKSTKRS,"
                    +"AMKPKST= :AMKPKST,"
                    +"AMKMTYP= :AMKMTYP,"
                    +"AMKMASCHZL= :AMKMASCHZL,"
                    +"AMKEINH= :AMKEINH,"
                    +"AMKFAKTOR= :AMKFAKTOR,"
                    +"AMKAKSTKRS= :AMKAKSTKRS,"
                    +"AMKAKST= :AMKAKST,"
                    +"AMKMNRKRS= :AMKMNRKRS,"
                    +"AMKMLFDNR= :AMKMLFDNR,"
                    +"AMKMPOS= :AMKMPOS,"
                    +"AMKANZ1= :AMKANZ1,"
                    +"AMKABT1= :AMKABT1,"
                    +"AMKANZ2= :AMKANZ2,"
                    +"AMKABT2= :AMKABT2,"
                    +"AMKANZ3= :AMKANZ3,"
                    +"AMKABT3= :AMKABT3,"
                    +"AMKANZ4= :AMKANZ4,"
                    +"AMKABT4= :AMKABT4,"
                    +"AMKANZ5= :AMKANZ5,"
                    +"AMKABT5= :AMKABT5,"
                    +"AMKANZ6= :AMKANZ6,"
                    +"AMKABT6= :AMKABT6,"
                    +"AMKANZ7= :AMKANZ7,"
                    +"AMKABT7= :AMKABT7,"
                    +"AMKANZ8= :AMKANZ8,"
                    +"AMKABT8= :AMKABT8,"
                    +"AMKFILLER= :AMKFILLER,"
                    +"AMKAENDZL= :AMKAENDZL,"
                    +"AMKAENDBEN= :AMKAENDBEN,"
                    +"AMKAENDDAT= :AMKAENDDAT,"
                    +"AMKNEUBEN= :AMKNEUBEN,"
                    +"AMKNEUDAT= :AMKNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("AMKMANDANT", OracleType.NVarChar).Value = dwData["AMKMANDANT"].ToString(); 
          or1.Parameters.Add("AMKPKSTKRS", OracleType.NVarChar).Value = dwData["AMKPKSTKRS"].ToString(); 
          or1.Parameters.Add("AMKPKST", OracleType.NVarChar).Value = dwData["AMKPKST"].ToString(); 
          or1.Parameters.Add("AMKMTYP", OracleType.NVarChar).Value = dwData["AMKMTYP"].ToString(); 
          or1.Parameters.Add("AMKMASCHZL", OracleType.NVarChar).Value = dwData["AMKMASCHZL"].ToString(); 
          or1.Parameters.Add("AMKEINH", OracleType.NVarChar).Value = dwData["AMKEINH"].ToString(); 
          or1.Parameters.Add("AMKFAKTOR", OracleType.NVarChar).Value = dwData["AMKFAKTOR"].ToString(); 
          or1.Parameters.Add("AMKAKSTKRS", OracleType.NVarChar).Value = dwData["AMKAKSTKRS"].ToString(); 
          or1.Parameters.Add("AMKAKST", OracleType.NVarChar).Value = dwData["AMKAKST"].ToString(); 
          or1.Parameters.Add("AMKMNRKRS", OracleType.NVarChar).Value = dwData["AMKMNRKRS"].ToString(); 
          or1.Parameters.Add("AMKMLFDNR", OracleType.NVarChar).Value = dwData["AMKMLFDNR"].ToString(); 
          or1.Parameters.Add("AMKMPOS", OracleType.NVarChar).Value = dwData["AMKMPOS"].ToString(); 
          or1.Parameters.Add("AMKANZ1", OracleType.NVarChar).Value = dwData["AMKANZ1"].ToString(); 
          or1.Parameters.Add("AMKABT1", OracleType.NVarChar).Value = dwData["AMKABT1"].ToString(); 
          or1.Parameters.Add("AMKANZ2", OracleType.NVarChar).Value = dwData["AMKANZ2"].ToString(); 
          or1.Parameters.Add("AMKABT2", OracleType.NVarChar).Value = dwData["AMKABT2"].ToString(); 
          or1.Parameters.Add("AMKANZ3", OracleType.NVarChar).Value = dwData["AMKANZ3"].ToString(); 
          or1.Parameters.Add("AMKABT3", OracleType.NVarChar).Value = dwData["AMKABT3"].ToString(); 
          or1.Parameters.Add("AMKANZ4", OracleType.NVarChar).Value = dwData["AMKANZ4"].ToString(); 
          or1.Parameters.Add("AMKABT4", OracleType.NVarChar).Value = dwData["AMKABT4"].ToString(); 
          or1.Parameters.Add("AMKANZ5", OracleType.NVarChar).Value = dwData["AMKANZ5"].ToString(); 
          or1.Parameters.Add("AMKABT5", OracleType.NVarChar).Value = dwData["AMKABT5"].ToString(); 
          or1.Parameters.Add("AMKANZ6", OracleType.NVarChar).Value = dwData["AMKANZ6"].ToString(); 
          or1.Parameters.Add("AMKABT6", OracleType.NVarChar).Value = dwData["AMKABT6"].ToString(); 
          or1.Parameters.Add("AMKANZ7", OracleType.NVarChar).Value = dwData["AMKANZ7"].ToString(); 
          or1.Parameters.Add("AMKABT7", OracleType.NVarChar).Value = dwData["AMKABT7"].ToString(); 
          or1.Parameters.Add("AMKANZ8", OracleType.NVarChar).Value = dwData["AMKANZ8"].ToString(); 
          or1.Parameters.Add("AMKABT8", OracleType.NVarChar).Value = dwData["AMKABT8"].ToString(); 
          or1.Parameters.Add("AMKFILLER", OracleType.NVarChar).Value = dwData["AMKFILLER"].ToString(); 
          or1.Parameters.Add("AMKAENDZL", OracleType.NVarChar).Value = dwData["AMKAENDZL"].ToString(); 
          or1.Parameters.Add("AMKAENDBEN", OracleType.NVarChar).Value = dwData["AMKAENDBEN"].ToString(); 
          or1.Parameters.Add("AMKAENDDAT", OracleType.NVarChar).Value = dwData["AMKAENDDAT"].ToString(); 
          or1.Parameters.Add("AMKNEUBEN", OracleType.NVarChar).Value = dwData["AMKNEUBEN"].ToString(); 
          or1.Parameters.Add("AMKNEUDAT", OracleType.NVarChar).Value = dwData["AMKNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
